package fid

// panic error

type PanicError int

const (
	PanicErrorAuth PanicError = iota
	PanicErrorUnlogin
)

type FrameworkError struct {
	PanicError  PanicError
	Description string
	Params      []string
}

func (fe *FrameworkError) Error() string {
	return fe.Description
}

// api error
type APIError interface {
	Code() int
	Message() string
	Fail() bool
}

type FidAPIError struct {
	msg  string
	code int
}

func (f FidAPIError) Code() int {
	return f.code
}

func (f FidAPIError) Message() string {
	return f.msg
}

func (f FidAPIError) Fail() bool {
	return f.Code() != 0
}

func NewAPIError(msg string, code int) APIError {
	return &FidAPIError{
		msg:  msg,
		code: code,
	}
}

var (
	ErrCodeNone = 0

	ErrCodeBadParam   = 910001
	ErrCodeBadRequest = 910002
	ErrCodeBadSession = 910004

	ErrCodeUnlogin = 910101
	ErrCodeAuth    = 910102
)

var (
	ErrNone = NewAPIError("", ErrCodeNone)

	ErrBadParam   = NewAPIError("请求参数错误", ErrCodeBadParam)
	ErrBadRequest = NewAPIError("未知的接口请求", ErrCodeBadRequest)
	ErrBadSession = NewAPIError("会话错误", ErrCodeBadSession)
	ErrUnlogin    = NewAPIError("用户未登录", ErrCodeUnlogin)
	ErrAuth       = NewAPIError("没有对应操作权限", ErrCodeAuth)
)
